/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2015
 */


package com.environment_pro.monitor.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.environment_pro.monitor.model.TbLogOperate;
import com.environment_pro.monitor.service.TbLogOperateService;
import com.environment_pro.monitor.util.StaticUtil;
import com.environment_pro.monitor.util.PageHelper;
import com.environment_pro.monitor.util.PageHelper.Page;

@Controller
@RequestMapping("/tbLogOperate")
public class TbLogOperateController extends BaseController {
	
	private static final Logger logger = Logger.getLogger(TbLogOperateController.class);

	@Autowired
	private TbLogOperateService tbLogOperateService;
	
	/**
	 * 获取所有列表 
	 * @param request
	 * @return
	 */
	@RequestMapping("/getAllTbLogOperate")
	public String getAllTbLogOperate(TbLogOperate tbLogOperate, HttpServletRequest request){
		//初始化分页 参数
		initPageParameter(request);
		//查询
		Page<TbLogOperate> mypage = tbLogOperateService.findAll(pageInfo,tbLogOperate);
		//返回查询条件和结果
		request.setAttribute("mypage", mypage);
		request.setAttribute("tbLogOperate", tbLogOperate);
		request.setAttribute("tbLogOperateList", mypage.getResult());
		//返回页面
		return "/TbLogOperate/allTbLogOperate";
	}
	
	/**
	 * 获取所有列表
	 * @param request
	 * @return
	 */
	@RequestMapping("/getAllTbLogOperateJson")
	@ResponseBody
	public List<TbLogOperate> getAllTbLogOperateJson(TbLogOperate tbLogOperate,HttpServletRequest request){
		//初始化分页 参数
		initPageParameter(request);
		Page<TbLogOperate> mypage = tbLogOperateService.findAll(pageInfo,tbLogOperate);
		
		return mypage.getResult();
	}
	
	/**
	 * 跳转到添加界面
	 * @param request
	 * @return
	 */
	@RequestMapping("/toAddTbLogOperate")
	public String toAddTbLogOperate(HttpServletRequest request){
		
		return "/TbLogOperate/addTbLogOperate";
	}
	/**
	 * 添加并重定向
	 * @param tbLogOperate
	 * @param request
	 * @return
	 */
	@RequestMapping("/addTbLogOperate")
	public String addTbLogOperate(TbLogOperate tbLogOperate,HttpServletRequest request){
		tbLogOperateService.save(tbLogOperate);
		this.saveLogOperate(request,"");
		logger.info("");
		return "redirect:/tbLogOperate/getAllTbLogOperate";
	}
	
	/**
	 *编辑
	 * @param tbLogOperate
	 * @param request
	 * @return
	 */
	@RequestMapping("/updateTbLogOperate")
	public String updateTbLogOperate(TbLogOperate tbLogOperate,HttpServletRequest request){
		
		if(tbLogOperateService.update(tbLogOperate)){
			//tbLogOperate = tbLogOperateService.findById(tbLogOperate.getId());
			request.setAttribute("tbLogOperate", tbLogOperate);
			this.saveLogOperate(request,"");
			return "redirect:/tbLogOperate/getAllTbLogOperate";
		}else{
			return "/error";
		}
	}
	/**
	 * 根据id查询单个
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping("/getTbLogOperate")
	public String getTbLogOperate(int id,HttpServletRequest request){
		
		request.setAttribute("tbLogOperate", tbLogOperateService.findById(id));
		return "/TbLogOperate/editTbLogOperate";
	}
	
	/**
	 * 根据id查询单个
	 * @param id
	 * @param request
	 * @return
	 */
	@RequestMapping("/getTbLogOperateJson")
	@ResponseBody
	public TbLogOperate getTbLogOperateJson(int id,HttpServletRequest request){
		return tbLogOperateService.findById(id);
	}
	
	/**
	 * 删除
	 * @param id
	 * @param request
	 * @param response
	 */
	@RequestMapping("/delTbLogOperate")
	public void delTbLogOperate(int id,HttpServletRequest request,HttpServletResponse response){
		String result = "{\"result\":\"error\"}";
		TbLogOperate tbLogOperate = tbLogOperateService.findById(id);
		if(tbLogOperateService.delete(id)){
			result = "{\"result\":\"success\"}";
		}
		this.saveLogOperate(request,tbLogOperate.toString());
		response.setContentType("application/json");
		this.saveLogOperate(request,"");
		try {
			response.getWriter().write(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

